Serialize/flatbuffer to program#18129
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18129
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below:
|
|
@pytorchbot label "partner: arm" |
|
@pytorchbot label "release notes: exir" |
|
@pytorchbot label ciflow/trunk |
|
To add these label(s) (ciflow/trunk) to the PR, please first approve the workflows that are awaiting approval (scroll to the bottom of this page). This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows. |
There was a problem hiding this comment.
Pull request overview
This PR extends the EXIR serialization stack by adding a direct FlatBuffers → Python Program reader and updating deserialization/tests to use it, continuing the move away from JSON/flatc roundtrips introduced in #17333.
Changes:
- Add
_flatbuffer_to_program()to deserialize FlatBuffer bytes directly intoexecutorch.exir.schema.Programdataclasses. - Switch
deserialize_pte_binary()and related tests to use the new direct reader. - Remove the legacy JSON/
flatcconversion helpers and their associated tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
exir/_serialize/_flatbuffer_program.py |
Adds direct FlatBuffers unpack-to-dataclass conversion (including generated-module alias patching) via _flatbuffer_to_program(). |
exir/_serialize/_program.py |
Updates deserialize_pte_binary() to use _flatbuffer_to_program() instead of FlatBuffer→JSON→dataclass conversion. |
exir/_serialize/_flatbuffer.py |
Removes JSON/flatc Program conversion helpers that are no longer referenced. |
exir/_serialize/test/test_program.py |
Updates segment-peek tests to use _flatbuffer_to_program() and adds a richer-type deserialization test. |
exir/_serialize/test/test_flatbuffer_program.py |
Simplifies roundtrip testing to only cover the direct Python path. |
exir/_serialize/test/test_flatbuffer.py |
Removes tests for the deleted JSON-to-FlatBuffer Program conversion path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| @@ -565,7 +637,7 @@ def test_round_trip_with_segments(self) -> None: | |||
| # this also implicity tests the case where we try parsing the entire | |||
There was a problem hiding this comment.
Typo in the comment: "implicity" should be "implicitly".
| # this also implicity tests the case where we try parsing the entire | |
| # this also implicitly tests the case where we try parsing the entire |
|
@JacobSzwejbka @lucylq
Please let me know if part 2 is too much. I made it a separate commit. Thanks |
|
@claude review this PR. |
|
Claude finished @digantdesai's task in 2m 24s —— View job Review of PR #18129
This is a well-structured two-commit PR. Commit 1 adds a direct FlatBuffer-to-Program reader; Commit 2 removes the now-redundant JSON/ Observations and Suggestions1. Typo in As Copilot noted, "implicity" should be "implicitly": # this also implicity tests the case where we try parsing the entire2. if union_origin is list and hasattr(val, "__iter__"):
return TrueThis matches any iterable value against any 3. if union_type is str and isinstance(val, (bytes, bytearray, memoryview)):
return TrueThis silently matches 4. Dead code left behind in After removing
So 5. Module-level caches are never cleared ( _T_CLASS_CACHE: Dict[type, type] = {}
_FIELD_NAME_CACHE: Dict[type, tuple[tuple[str, str], ...]] = {}
_TYPE_HINTS_CACHE: Dict[type, Dict[str, Any]] = {}These module-level dicts grow monotonically. In the normal ExecuTorch workflow (export once, serialize, done) this is fine. But in long-running processes or test suites that exercise many different schemas, they never shrink. This is not a bug -- just noting it for awareness. The existing 6. This function replaces module-level names (e.g., 7. if isinstance(expected_type, type):
return expected_type(val)This is the last-resort conversion at the bottom of 8. The special handling for Test CoverageThe test changes are solid:
SummaryThe PR is well-organized and the implementation is correct. The main actionable items are:
Everything else is minor or informational. Good work continuing the migration away from the |
digantdesai
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks. Did not know about the earlier serialization work and the awesome speedup, I was OOO. Awesome!
|
@chizkiyahu whats next here? |
6854de5 to
347eaa5
Compare
347eaa5 to
b32de31
Compare
This continues the work from pytorch#17333. Change-Id: I35ac4cd5f6430ea89939453344c13e056b5c746c Signed-off-by: Chizkiyahu Raful <chizkiyahu.raful@arm.com>
Change-Id: Iebb6ff9151b76b352ef5dbb4d9bd23e2e622c326 Signed-off-by: Chizkiyahu Raful <chizkiyahu.raful@arm.com>
b32de31 to
3040dc3
Compare
|
|
|
@digantdesai |
exir: add flatbuffer-to-program reader
This continues the work from #17333.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani